package com.itheima.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.entity.AddressBook;
import com.itheima.jsonresult.JsonResult;
import com.itheima.service.AddressBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author linying
 * @since 2022-10-13
 */
@RestController
@RequestMapping("/addressBook")
public class AddressBookController {

    @Autowired
    private AddressBookService addressBookService;

    /**
     * 添加收货地址
     * @param addressBook
     * @return
     */
    @PostMapping
    public JsonResult add(@RequestBody AddressBook addressBook) {
        return addressBookService.add(addressBook);
    }

    /**
     * 修改收货地址
     * @param addressBook
     * @return
     */
    @PutMapping
    public JsonResult put(@RequestBody AddressBook addressBook) {
        return addressBookService.put(addressBook);
    }

    /**
     * 删除收货地址
     * @param ids
     * @return
     */
    @DeleteMapping
    public JsonResult delete(String ids) {
        return addressBookService.delete(ids);
    }

    /**
     * 获取默认地址
     * @return
     */
    @GetMapping("/default")
    public JsonResult def() {
        return addressBookService.def();
    }

    /**
     * 设置默认地址
     * @param addressBook
     * @return
     */
    @PutMapping("/default")
    public JsonResult setdef(@RequestBody AddressBook addressBook) {
        return addressBookService.setdef(addressBook);
    }


    /**
     * 获取收货地址列表
     * @return
     */
    @GetMapping("/list")
    public JsonResult list() {
        return addressBookService.addressBookList();
    }

    /**
     * 根据id获取收货地址
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public JsonResult getById(@PathVariable String id) {
        return addressBookService.getAddressBookById(id);
    }


}
